<html>
<head><meta charset="utf-8"><title>cargo-workspace-root-env · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cargo-workspace-root-env.html">cargo-workspace-root-env</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="169557185"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cargo-workspace-root-env/near/169557185" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> csmoe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cargo-workspace-root-env.html#169557185">(Jul 03 2019 at 11:10)</a>:</h4>
<p>for a workspace:</p>
<div class="codehilite"><pre><span></span>workspace -
   - Cargo.toml
   - crate_a
      - Cargo.toml
      - build.rs
   - crate_b
</pre></div>


<p><span class="user-mention" data-user-id="133169">@matklad</span> is there any method for <code>crate_a/build.rs</code> to get the <code>workspace</code>'s root path with env variable? <code>CARGO_MANIFEST_DIR</code> can only return the path of <code>crate_a</code>.</p>



<a name="169557459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cargo-workspace-root-env/near/169557459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cargo-workspace-root-env.html#169557459">(Jul 03 2019 at 11:17)</a>:</h4>
<p>IIRC, that's not possible in a good. I remember facing the same issue with <code>insta</code>. The workaround is to call <code>cargo metadata</code> from <code>build.rs</code></p>



<a name="169557519"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cargo-workspace-root-env/near/169557519" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> csmoe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cargo-workspace-root-env.html#169557519">(Jul 03 2019 at 11:18)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> thanks <span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span><br>
 is it suitable to post a feature request to cargo repo?</p>



<a name="169557644"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cargo-workspace-root-env/near/169557644" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cargo-workspace-root-env.html#169557644">(Jul 03 2019 at 11:21)</a>:</h4>
<p>Yeah, I think <code>CARGO_WORKSPACE_MANIFEST_DIR</code> is a reasonable thing to add to Cargo. The insta issue was <a href="https://github.com/mitsuhiko/insta/issues/1" target="_blank" title="https://github.com/mitsuhiko/insta/issues/1">https://github.com/mitsuhiko/insta/issues/1</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>